from mnemoply.model.model_object import ModelObject
from mnemoply.model.hub import __connection__
from mnemoply._renewed_model.columns import  UnicodeCol, BoolCol,\
                        ForeignKey, DateCol, TimeCol, IntCol,\
                        BLOBCol, DecimalCol
from sqlobject import DatabaseIndex
from datetime import datetime, date, timedelta

class SmallDictionary(ModelObject):
    model_title = _("")
    name = UnicodeCol(length=80, notNull=True, title=_("Name"))
    title =  property(lambda self:self.name)

class CameFrom(SmallDictionary):
    model_title = _("Came from")
    class sqlmeta:
        table = "prod_v2.came_from"

class StudentType(SmallDictionary):
    model_title = _("StudentType")
    class sqlmeta:
        table = "prod_v2.student_type"

class PriceFor(SmallDictionary):
    model_title = _("PriceFor")
    class sqlmeta:
        table = "prod_v2.price_for"

class AuditObjectClass_new(SmallDictionary):
    model_title = "Audit!ObjectClass"

class PartnerType_new(SmallDictionary):
    """
        Partner type dictionary. Contains values `default`, `student`, `personal`.
    """

    model_title = _("Partner type")

class DocumentType_new(SmallDictionary):
    """
        Contains min works and min hours for creation document with this type.
    """

    model_title = _("Document type")
    minHours = IntCol(notNull=True, title=_("Minimum hours"))
    minWorks = IntCol(notNull=True, title=_("Minimum works"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Qualification_new(SmallDictionary):

    model_title = _("Qualification")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Specialization_new(SmallDictionary):
    model_title = _("Specialization")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Position_new(SmallDictionary):
    """
        Position for person. 
    """

    model_title = _("Position")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class PhoneCode_new(SmallDictionary):
    """
        Possible code from operators
    """

    model_title = _("Phone codes")

    value = UnicodeCol(length=5, notNull=True, alternateID=True, title=_("Value"))

class CashRegister_new(SmallDictionary):
    """Cash register representation."""

    model_title = _("Cash register")

    office = ForeignKey('Office', notNull=True, title=_("Office"))
    organization = ForeignKey('Organization', notNull=True, title=_("Organization"))

    uniqueName = DatabaseIndex('name', unique=True)
    uniqueOfficeOrganization = DatabaseIndex('office', 'organization', unique=True)

class CashRegisterDepartmentName_new(SmallDictionary):
    """Names for cash register departments."""

    model_title = _("Cash register department name")

    nameUnique = DatabaseIndex('name', unique=True)

class ServiceType_new(SmallDictionary):
    """Type of one-time service."""

    model_title = _("Service type")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class CouponType_new(SmallDictionary):
    """Coupon type."""

    model_title = _("Coupon type")

    nominal = IntCol(notNull=True, title=_("Nominal"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))
    year = IntCol(notNull=True, title=_("Year"), default=date.today().year)

class Faculty_new(SmallDictionary):
    """
        Education department representation.
    """
    model_title = _("Faculty")
    abbr = UnicodeCol(length=3, notNull=True, unique=True, title=_("Letter"))

class PaymentType_new(SmallDictionary):
    """
        this is one of the characteristics of trend 
    """
    model_title = _("Payment type")
    abbr = UnicodeCol(length=3, notNull=True, unique=True, title=_("Letter"))

class TestType_new(SmallDictionary):
    """
        Type of scholarship tests.
    """

    model_title = _("Test type")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Trend_new(SmallDictionary):
    """
        Education trend representation.
    """

    model_title = _("Trend")

    oneChar = UnicodeCol(length=10, notNull=True, unique=True, title=_("Letter"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))
    paymentType = ForeignKey('PaymentType', notNull=True, title=_("Payment type"))
    faculty = ForeignKey('Faculty', notNull=True, title=_("Faculty"))

class DischargeReason_new(SmallDictionary):
    """
        Describe why we discharge student from group.
    """

    model_title = _("Discharge reason")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class MarkType_new(SmallDictionary):
    """
        Student mark type.
    """

    model_title = _("Mark type")

   
    name_ms = UnicodeCol(length=80, notNull=True, default='', title=_("MS IT name"))
    name_ms_rus = UnicodeCol(length=80, notNull=True, default='', title=_("MS IT name (russian)"))
    name_rus = UnicodeCol(length=80, notNull=True, default='', title=_("Name (russian)"))
    bad_mark = BoolCol(notNull=True, default=False, title=_("Bad mark?"))
    hide_mark = BoolCol(notNull=True, default=False, title=_("Hide mark?"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class BusynessType_new(SmallDictionary):
    """
        Full employment or underemployment. Really need for persons.
    """

    model_title = _("Busyness type")

   
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class ClassroomType_new(SmallDictionary):
    """
        Maybe standard or multimedia.
    """

    model_title = _("Classroom type")

   
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Organization_new(SmallDictionary):
    """
        Simple organization representation.
        Contains information for reports, such as address or some codes.
    """

    model_title = _("Organization")

    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))


    fullName = UnicodeCol(default='', notNull=True, title=_("Full name"))
    address = UnicodeCol(default='', notNull=True, title=_("Address"))

    codeOcato = UnicodeCol(length=100, notNull=True, title=_("OCATO"))
    codeOcpo = UnicodeCol(length=100, notNull=True, title=_("OCPO"))
    codeInn = UnicodeCol(length=100, notNull=True, title=_("INN"))
    codeKpp = UnicodeCol(length=100, notNull=True, title=_("KPP"))

    directorName = UnicodeCol(length=100, notNull=True, title=_("Director name"))
    regalia = UnicodeCol(length=100, notNull=True, title=_("Regalia"))

class AgreementType_new(SmallDictionary):
    """
        Describes short-time or standard-long courses.
    """

    model_title = _("Agreement type")

class CertificateType_new(SmallDictionary):
    """
        Certificate type. Need for English groups.
    """

    model_title = _("Certificate type")

   
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class TestName_new(SmallDictionary):
    """
        Test. Test work by some plan.
    """

    model_title = _("Test name")

   
    plan = ForeignKey('Plan', notNull=True, title=_("Plan"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class Office_new(SmallDictionary):
    """
        UCVT's office.
        Abbreviation need for partner's password generation.
    """

    model_title = _("Office")

   
    ordinal = IntCol(notNull=True, title=_("Ordinal"))
    address = UnicodeCol(length=120, notNull=True, title=_("Address"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))
    abbreviation = UnicodeCol(length=80, default='', title=_("Abbreviation"))
    organization = ForeignKey('Organization', notNull=True, title=_("Organization"))
    
    ordinalUnique = DatabaseIndex('ordinal', unique=True)

class Topic_new(SmallDictionary):
    """
        Education topic.
    """

    model_title = _("Topic")

    responsibleTeacher = ForeignKey('Person', default=None, title=_("Responsible teacher"))
    trend = ForeignKey('Trend', notNull=True, title=_("Trend"))
    finalTest = ForeignKey('TestType', notNull=True, title=_("Final test"))
    isFinalWork = BoolCol(notNull=True, default=False, title=_("Is final work"))
    shouldBeAMark = BoolCol(notNull=True, default=False, title=_("Should be a mark"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))

class FinalWorkTopic_new(SmallDictionary):
    """
        Topic for final work.
        Students in one group have differents final works and different final works topics.
    """

    model_title = _("Final work topic")

    topic = ForeignKey('Topic', notNull=True, title=_("Topic"))
    comment = UnicodeCol(default='', notNull=True, title=_("Comment"))
